<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>企业用户</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="css/layui.css" rel="stylesheet"  media="all">
</head>
<body>

<table id="company-user-list"></table>

<script type="text/html" id="toolbarDemo">
  <div class="layui-inline">
    <input class="layui-input" name="keywords" id="keywords" placeholder="请输入用户名称或电话" autocomplete="off" lay-affix="clear">
  </div>
  <button class="layui-btn" lay-event="search">搜索</button>
  <button class="layui-btn layui-btn-sm" lay-event="btnExport">全部导出</button>
</script>

<script src="js/layui.js"></script>
<script type="module">
    import companyUser from './js/register-user.js'
    
    layui.use(['table', 'layer', 'form'], function () {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;

        // 加载企业用户列表
        var loadCompanyUserList = function(keywords,isExport){
            companyUser.getUserList($,keywords,function(rspData){
            //表格数据渲染
            var insTable = table.render({
                elem: '#company-user-list'
                ,title:'企业用户列表'
                ,toolbar:'#toolbarDemo'
                ,width: 1000
                ,height: 600
                ,cols: [[{ type:"numbers", width:80, title: '序号', sort: true, fixed: 'left'}
                ,{field:'id', hide:true}
                ,{field:'nickName', width:200, title: '用户名称'}
                ,{field:'phoneNumber', width:120, title: '电话'}
                ,{field:'email', width:200, title: '邮箱' }
                ,{field:'region', width:200, title: '区域'}
                ,{field:'createTime', width:160, title: '创建时间'}
                ]]
                ,data: rspData.data
                ,done:function(){
                    $('#keywords').val(keywords);
                }
                ,even: true
                ,page: true //是否显示分页
                ,limits: [20,50,100]
                ,limit: 20 //每页默认显示的数量
                });
                if(isExport){
                    table.exportFile(insTable.config.id,rspData.data,'xls');
                }
            })
        }
        loadCompanyUserList(null);

        // 工具栏事件
        table.on('toolbar(company-user-list)', function(obj){
            switch(obj.event){
                case 'search':
                    var keywords = $('#keywords').val();
                    loadCompanyUserList(keywords);
                break;
                case 'btnExport':
                    var keywords = $('#keywords').val();
                    loadCompanyUserList(keywords,true);
                break;
            };
        });
    });
</script>
</body>

</html>